package o;

import android.content.Context;
import android.content.SharedPreferences.Editor;
import androidx.annotation.NonNull;
import com.huawei.appgallery.essentialapp.api.EssentialAppDataBean;
import com.huawei.appgallery.essentialapp.api.EssentialAppDataBean.OneAppInfoBean;
import com.huawei.appgallery.foundation.card.base.bean.AppInfoBean;
import com.huawei.hmf.annotation.ApiDefine;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@ApiDefine(uri = bqh.class)
public class bqi implements bqh, bqp {
    private static bqi ʼ;
    private bqk ʽ;
    private int ˊ = 0;
    private ArrayList<OneAppInfoBean> ˋ = new ArrayList();
    private EssentialAppDataBean ˎ;
    private bqg ˏ;
    private int ॱ = 0;

    static class e {
        public static boolean ॱ() {
            boolean z = true;
            bqn.ˏ();
            if (!cep.ˏ()) {
                return false;
            }
            boolean z2 = !cep.ॱ() && cep.ˋ() && ˊ().equals(bqn.ˎ());
            if (z2) {
                return false;
            }
            if (0 == bqn.ˊ()) {
                z2 = true;
            } else {
                z2 = false;
            }
            Context ˋ = ContentManager.getInstant().getContext();
            if (!(z2 && bmt.ˊ(ˋ))) {
                z = false;
            }
            return z;
        }

        public static String ˊ() {
            String str = "";
            try {
                Context ˋ = ContentManager.getInstant().getContext();
                str = ˋ.getPackageManager().getPackageInfo(ˋ.getPackageName(), DnsConfig.MAX_CACHE_ENTRIES).versionName;
            } catch (Throwable e) {
                bqb.ˋ.ˊ("ShowLogicHelperLog", "can not find versionName", e);
            }
            Matcher matcher = Pattern.compile("^[0-9a-zA-Z]+\\.[0-9a-zA-Z]+\\.[0-9a-zA-Z]{1}").matcher(str);
            if (matcher.find()) {
                return matcher.group(0);
            }
            bqb.ˋ.ˊ("ShowLogicHelperLog", "can not find versionName:" + str);
            return str;
        }
    }

    public bqi() {
        ॱ(this);
    }

    private static void ॱ(bqi o_bqi) {
        ʼ = o_bqi;
    }

    public static bqp ʼ() {
        return ʼ;
    }

    public void ˏ(EssentialAppDataBean essentialAppDataBean) {
        ॱ(essentialAppDataBean);
    }

    public int ˋ() {
        return this.ˎ == null ? 0 : this.ˎ.ˊ();
    }

    private boolean ˏ(@NonNull AppInfoBean appInfoBean) {
        return ((cdg) cdb.ॱ(cdg.class)).ॱॱ(appInfoBean.ˏॱ()) || (!HcridSession.ˋ().appsstoreGMSSupport() && 1 == appInfoBean.getGmsSupportFlag());
    }

    public boolean ˎ() {
        return e.ॱ() && ॱᐝ();
    }

    public void ॱ() {
        String ˊ = e.ˊ();
        Editor edit = cfo.ˏ(ContentManager.getInstant().getContext(), "EssentialApp", 0).edit();
        edit.putString("LAST_VER_HOMEPAGE_ENTER", ˊ).apply();
        if (this.ॱ != 0) {
            edit.putBoolean("HAS_WLAN_UPDATE_SHOWED", true).apply();
        }
    }

    public boolean ˊ() {
        return 1 == this.ॱ;
    }

    public boolean ʽ() {
        return this.ॱ != 0;
    }

    public boolean ˏ() {
        return 1 == this.ˊ;
    }

    public boolean ʻ() {
        return this.ˊ != 0;
    }

    public void ˊ(bqg o_bqg) {
        this.ˏ = o_bqg;
    }

    public EssentialAppDataBean ᐝ() {
        return this.ˎ;
    }

    public void ˊ(EssentialAppDataBean essentialAppDataBean) {
        ॱ(essentialAppDataBean);
    }

    public void ॱ(int i) {
        this.ॱ = i;
    }

    public int ॱॱ() {
        return this.ॱ;
    }

    public void ˋ(int i) {
        this.ˊ = i;
    }

    public int ˊॱ() {
        return this.ˊ;
    }

    public boolean ˏॱ() {
        return cfo.ˏ(ContentManager.getInstant().getContext(), "EssentialApp", 0).getBoolean("HAS_WLAN_UPDATE_SHOWED", false);
    }

    public List<OneAppInfoBean> ˋॱ() {
        return this.ˋ;
    }

    public bqg ͺ() {
        return this.ˏ;
    }

    private void ॱ(EssentialAppDataBean essentialAppDataBean) {
        if (essentialAppDataBean == null) {
            essentialAppDataBean = new EssentialAppDataBean();
            essentialAppDataBean.ˎ(0);
        }
        this.ˎ = essentialAppDataBean;
        ॱˋ();
    }

    private void ॱˋ() {
        boolean z = false;
        int i = 1;
        if (this.ˎ != null) {
            this.ˋ.clear();
            this.ˎ.ˏ(false);
            int ॱ = this.ˎ.ॱ();
            if (ॱ == 2) {
                List ˊ = ˊ(this.ˎ.ˏ(), this.ˎ.ʼ(), 2);
                this.ˎ.ॱ(ˊ);
                if (ˊ.size() < this.ˎ.ᐝ()) {
                    z = true;
                }
            } else {
                this.ˎ.ॱ(null);
            }
            if (ॱ == 1 || z) {
                List ˋ = this.ˎ.ˋ();
                if (!CollectCheck.isEmpty(ˋ)) {
                    int ʻ = this.ˎ.ʻ();
                    if (z) {
                        i = 3;
                    }
                    this.ˎ.ˎ(ˊ(ˋ, ʻ, i));
                }
            } else {
                this.ˎ.ˎ(null);
            }
            this.ˎ.ˎ();
        }
    }

    private List<OneAppInfoBean> ˊ(List<OneAppInfoBean> list, int i, int i2) {
        List<OneAppInfoBean> arrayList = new ArrayList();
        Collection arrayList2 = new ArrayList();
        int size = list == null ? 0 : list.size();
        int i3 = 0;
        int i4 = 0;
        int i5 = 0;
        while (i3 < size) {
            AppInfoBean appInfoBean = (OneAppInfoBean) list.get(i3);
            if (!ˏ(appInfoBean)) {
                i4++;
                appInfoBean.ˊ(i4);
                appInfoBean.ॱ(i2);
                arrayList.add(appInfoBean);
                if (i5 < i) {
                    appInfoBean.ॱ(true);
                    arrayList2.add(appInfoBean);
                    i5++;
                }
                if (appInfoBean.ˊ() == 1) {
                    ᐝ().ˏ(true);
                }
            }
            i3++;
            i4 = i4;
        }
        this.ˋ.addAll(arrayList2);
        return arrayList;
    }

    public void ॱˊ() {
        Editor edit = cfo.ˏ(ContentManager.getInstant().getContext(), "EssentialApp", 0).edit();
        edit.putLong("LASG_TIME_ESSENTIALAPP_QUIT", System.currentTimeMillis());
        edit.apply();
    }

    private boolean ॱᐝ() {
        if (this.ʽ != null) {
            return this.ʽ.ˋ();
        }
        return true;
    }
}
